//
//  Operator_Overloading.cpp
//  learnC++
//
//  Created by apple on 2018/6/4.
//  Copyright © 2018年 yunfan.com. All rights reserved.
//

#include "Operator_Overloading.hpp"

//重载plus操作符（+）非常简单，只需声明一个名为operator +的函数，给它两个我们想要添加的操作数类型的参数，选择适当的返回类型，然后编写该函数。
// note: this function is not a member function!
CentsTwo operator+(const CentsTwo &c1, const CentsTwo &c2)
{
    // use the CentsTwo constructor and operator+(int, int)
    // we can access m_cents directly because this is a friend function
    return CentsTwo(c1.m_cents + c2.m_cents);
}

CentsTwo operator-(const CentsTwo &c1,const CentsTwo &c2){
    return CentsTwo(c1.m_cents - c2.m_cents);
}

// note: this function is not a member function!
CentsTwo operator+(const CentsTwo &c1, int value)
{
    // use the Cents constructor and operator+(int, int)
    // we can access m_cents directly because this is a friend function
    return CentsTwo(c1.m_cents + value);
}

// note: this function is not a member function!
CentsTwo operator+(int value, const CentsTwo &c1)
{
    // use the Cents constructor and operator+(int, int)
    // we can access m_cents directly because this is a friend function
    return CentsTwo(c1.m_cents + value);
}

